package bin_tree.leetcode;

/**
 * 判断两棵树是否是相同的树
 * @author yuisama
 * @date 2022/02/20 14:38
 **/
public class Num100_SameTree {
    /**
     * 传入两颗树p和q我就能判断p和q是否是相同的树
     * @param p
     * @param q
     * @return
     */
    public boolean isSameTree(TreeNode p, TreeNode q) {
        // 边界条件
        if (p == null && q == null) {
            // 两棵树都是空树
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        return p.val == q.val &&
                isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}